Allow printing of a length-0 coordinate (#6531)#7122
Conversation
7784187 to
3f3d312
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7122 +/- ##
=======================================
Coverage 90.15% 90.15%
=======================================
Files 91 91
Lines 24985 24985
Branches 4685 4685
=======================================
Hits 22526 22526
Misses 1682 1682
Partials 777 777 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ukmo-ccbunney
left a comment
There was a problem hiding this comment.
Changes to the code look good - thank you @gaoflow. 👍🏼
There are some updates required regarding the What's New, but I see that you have already been applying those to your other PRs - top points for that! 💯
Are you happy to make the same updates here?
If not, please do say and I'll raise a PR against your branch.
Coord.summary() formats string and date-like values by first finding the longest string with max(...), which raised ValueError on an empty array. A length-0 coordinate is a valid object (e.g. a time coordinate for an unfilled unlimited dimension), so its summary should not crash. Pass default=0 to max() so an empty array formats as '[]'. Fixes SciTools#6531.
3f3d312 to
b568535
Compare
|
Updated this PR for the new towncrier changelog layout and rebased onto current Changes in
Verification after the rebase: ruff check lib/iris/coords.py lib/iris/tests/unit/coords/test_Coord.py
ruff format --check lib/iris/coords.py lib/iris/tests/unit/coords/test_Coord.py
uv run --with pytest --with pytest-mock --with requests --with filelock --with-editable . python -m pytest lib/iris/tests/unit/coords/test_Coord.py::Test___str__::test_empty_time_coord lib/iris/tests/unit/coords/test_Coord.py::Test___str__::test_empty_string_coord -q
uv run --with towncrier towncrier build --draft --version 0.0
git diff --check origin/main...HEAD |
ukmo-ccbunney
left a comment
There was a problem hiding this comment.
Thank you @gaoflow for taking the time to rebase and update you branch. 💯
Changes look good. LGTM. 🚀
🚀 Pull Request
Description
Closes #6531.
Printing a length-0 coordinate raised a
ValueErrorinstead of producing a summary:As confirmed by @SciTools/peloton on the issue, a length-0 time coordinate is a valid object — it represents an unlimited dimension that does not yet have any points — so printing it should not crash.
Cause
Coord.summary()formats string- and date-like values by first finding the longest element so it can apply a common width:For an empty array this generator is empty, so
max()raises. (Date-like coordinates reach this branch becausenum2dateconverts the points to strings first; the original report'svectorize/otypeserror no longer occurs with currentcf-units, leaving thismax()call as the remaining failure.)Fix
Pass
default=0tomax(), so an empty array yields a zero width and formats as[]. Non-empty coordinates are unaffected.Verification
Test___str__::test_empty_time_coordand::test_empty_string_coord(both date-like and plain-string empty paths). They fail onmainand pass here.tests/unit/coords/andtests/unit/representation/suites pass (470 tests).ruff check/ruff formatclean.